home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
internet
/
yam_i_dodatki
/
yamnet
/
fscode.doc
< prev
next >
Wrap
Text File
|
1996-05-10
|
10KB
|
224 lines
NAME
FSCode -- Encode a binary file using only ASCII characters.
SYNOPSIS
FSCode FILE/A,TO,E=ENCODE/S,MULTI/S,LINES/N
FUNCTION
FSCode was born to be a more efficient replacement for uuencode;
it's purpose is to encode a binary file (for example, an executable
or an archive such as those made by LhA or Zip) using only the
standard ASCII character set, i.e. the characters between 32 and 126.
uuencode encodes 3 bytes into 4 characters, enlarging a file by
33%; FSCode does a better job by encoding 4 bytes (a longword) into
5 characters: the enlargement is only 25%. This theoretical figure
does not take into account a couple of control lines and the line
feeds used to subdivide the resulting file, and two more control
characters per line needed by uuencode; the real enlargement tends
to 26.6...% for FSCode and to 37.7...% for uuencode.
It must be made clear that the quantity of information contained in
the encoded files is exactly the same, so, if you use uuencode or
FSCode to send binary files into electronic mail messages that will
be compressed thereafter, the size of the resulting packets will be
very similar, in perfect accordance to the information theory. The
advantage is that the message stored on your disk in readable form
will take less space, and that you will be able to send bigger
files when there is a limit on the size of a single message.
One more advantage of FSCode over uuencode is that it uses a 32-bit
CRC to check the correctness of the decoded file; one disadvantage
is that it doesn't use a per-line checksum, so you won't know
exactly where the file was corrupted.
INPUTS
FILE - Input file to encode or decode.
The file to decode can contain multiple encoded files and/or
multiple parts of a single file (read further for details).
TO - Destination file for the encoded or decoded data (optional).
If the destination file is omitted, FSCode will send it's
output to the standard output (usually the console) when
encoding, or to the file name specified in the encoded file
when decoding.
CAUTION: If you specify a destination filename and the file to
decode contains multiple encoded files, they will be appended
to the same file, which might not be what you want. It is
usually better to omit the destination filename and let FSCode
figure out the correct name as written in the encoded file.
E=ENCODE - A switch that instructs FSCode to encode the input file.
By default FSCode will try to decode an already encoded file
and recreate the original file.
M=MULTI - Encode/decode to/from a multi-part file.
If encoding, FSCode will split the file in blocks made by a
given number of lines (see the LINES parameter below). If you
specified a destination file name, FSCode will place every
block in a separate file, using the specified file name as the
base part and appending a number: for example, if you specified
"Hello" as the destination file name, FSCode will create
"Hello1", Hello2", and so on. If you didn't specify a
destination file name, the blocks will be sent to the standard
output one after another. If the file is small enough to fit in
a single block, FSCode will automatically switch back to
single-part mode.
If decoding, the MULTI switch instructs FSCode to read several
files as input: again, FSCode will use the input file name as
the base part and append a number. Please note that you don't
have to use the MULTI switch to decode a multi-part file placed
in a single input file: FSCode is smart enough to recognize it
and skip any extraneous data. On the other hand, you can decode
several single-part files at once by giving them suitable names
and invoking FSCode with the MULTI option.
L=LINES - Set number of lines for multi-part encoding.
The default is 100 lines, which is just below 8 kb. The
starting and ending lines are not included, so the resulting
file will be LINES+2 lines long. The minimum value for this
parameter is 2.
This parameter is meaningful only when encoding.
RESULT
FSCode will output a file that looks like this:
!start Example
E4x~n4MPvGMo9KC4L]7:J^.a,N5B2E###*4
!end 25 4E9AB940
The first line contains the file name, without drive/directory
specifications. This is to prevent 1) errors when trying to decode
a file produced on a system different than yours and 2) funny jokes
like overwriting system files. The decoding process actually uses
the complete file name, without removing the drive/directory part
that might have been added after the encoding: this is to ease the
creation of scripts and such things for automatic decoding.
The last line contains the size (in decimal) and the 32-bit CRC (in
hexadecimal) of the original file.
In multi-part mode, each part starts with a line like this:
!mstrt 1/2 Example
where "1/2" means "this is part 1 of a 2-parts file". Notice that
the magic word is "!mstrt" instead of "!start". The "!end" line has
the same format in both modes: the only difference is that the size
and CRC values are partial, i.e. only for the preceeding blocks. It
has been done this way so that you will know which part is wrong in
case of a problem.
Should FSCode fail for any reason, an (hopefully) meaningful
message will be printed on your screen. Examples include `no start
line' or `CRC mismatch' or `can't open file <file name>'.
NOTES
FSCode is very tolerant on what you do to the encoded lines,
provided that you do not add or remove characters in the range from
33 to 126 [!-~]. You can reflow the lines and insert spaces, line
feeds or other control characters at will.
FSCode reports inconsistencies in size or CRC but continues the
decoding process, so if the problem is real you can at least
recover part of the file.
The absence of the "!end" line does not influence the correctness
of the decoded file, provided that no characters that could be
taken as valid follow the real data. Of course you miss the size
and CRC check, but otherwise the decoding process is not influenced.
In multi-part mode, FSCode will not create the last file if it
would contain only one line of data: it will append that line to
the previous file, which will then be one line longer than
expected.
You can create a single-part file from a multi-part one by
following these simple steps:
* join all the parts together;
* remove all the "!mstrt" and "!end" lines except for the first
"!mstrt" line and the last "!end" line, and any spurious data
that might be floating around inbetween two parts;
* change the first "!mstrt x/y" line to "!start" (in other
words, make it look like as a single-part starting line).
For a deeper description of the encoding algorithm, see the file
`Specs.Doc' and the source code.
HISTORY
37.? - Changed initialization of CRC-32 table from static to
dynamic. This saves 1 kb of executable size.
37.16 - Added a couple of SetVBuf() calls: this should speed up I/O
on kickstart V40 and above. SetVBuf() is not implemented on
prior kickstart versions, but it is harmless to call.
37.17 - Minor improvements, so minor I don't even remember them. ;)
37.18 - Major improvements, including:
* support for automatic splitting and joining;
* made faster thanks to improved I/O strategies;
* can be aborted by pressing CTRL-C;
* more robust error checking (I hope).
Moreover, the ExtractFile.ems script now checks for the
presence of the ending line before it starts extraction. The
previous versions would hang in such a case.
37.19 - The decoder automatically extracts multiple encoded files
placed in the same input file(s). Somehow I forgot to add this
nice feature in the previous release.
37.20 - Minor change in CRC-32 routines, affecting only code size.
FSCode is now completely pure. Previously it wasn't, but it
worked fine as a residnet program anyway.
DISTRIBUTION
This program is freeware. You may redistribute it as long as:
- this text and the source code are included;
- you don't charge more than a nominal copying fee for
distribution.
Please state your modifications to the code with a clear comment,
and send me your modified version. It would be a good idea to
include the original code, anyway.
Any contribution will be greatly appreciated.
DISCLAIMER
The author does not assume any responsibility for damages which
could result by the use or possession of this program. The entire
risk for the use of this program is assumed by the user.
AUTHOR
Flavio Stanchina
Loc. Montevaccino, 39
38040 Trento (Italia)
Fidonet: 2:333/801.9@fidonet
e-mail: flavio@iestn.inet.it
ACKNOWLEDGEMENTS
Thanks to Gian Maria Calzolari (2:332/508.19@fidonet.org) for beta
testing and suggestions, and for writing a new ExtractFile.ems
ARexx script for EMS that supports both uuencode and FSCode.
Thanks to Marco Amadori (2:333/408.23@fidonet.org) for beta
testing, and for the modified UUDecode.spot and UUWrite.spot ARexx
scripts that support both uuencode and FSCode.
Thanks to Sandro Tolaini (2:332/113.3@fidonet.org) for a bug
report.
Thanks to Vincenzo Scarpa (2:334/21.20@fidonet.org) for
FSDecode.spot and FSWrite.spot (so, Spot users, now you have a
choice).
And finally thanks to all the participants of the AMIGA.ITA Fidonet
conference for suggestions and encouragement.